<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px" size="medium"
             class="ry_form"
    >
            <el-form-item label="商品名" prop="productName">
              <el-input
                v-model="queryParams.productName"
                placeholder="商品名"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="联系电话" prop="contactPhone">
              <el-input
                v-model="queryParams.contactPhone"
                placeholder="联系电话"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
      <el-form-item class="flex_one tr">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="OmsOrderInfoList" @selection-change="handleSelectionChange" border
              cell-class-name="my-cell"
    >
      <el-table-column label="订单编号" prop="orderNum"/>
      <el-table-column label="商品名" prop="productName"/>
      <el-table-column label="商品数量" prop="productCount"/>
      <el-table-column label="联系人" prop="contactUserName"/>
      <el-table-column label="联系电话" prop="contactPhone"/>
      <el-table-column label="单位名称" prop="companyName"/>
      <el-table-column label="快递地址" prop="shippingAddress"/>
      <el-table-column label="下单时间" prop="createTime"/>
      <!--      <el-table-column label="标记时间" prop="markTime"/>-->
      <!--      <el-table-column label="标记记录" prop="markRemarks"/>-->
      <el-table-column label="标记状态" align="center" prop="markStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mark_status" :value="scope.row.markStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdatehandle(scope.row)"
            v-if="scope.row.markStatus === 1"
            v-hasPermi="['oms:orderInfo:handle']"
          >客服处理
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdateSend(scope.row)"
            v-if="scope.row.markStatus === 2"
            v-hasPermi="['oms:orderInfo:send']"
          >已发货
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdatePayment(scope.row)"
            v-if="scope.row.markStatus === 3"
            v-hasPermi="['oms:orderInfo:payment']"
          >已收款
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['oms:orderInfo:updata']"
          >修改
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <InBody v-show="total>0">
      <pagination
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </InBody>


    <!-- 添加或修改公告对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
      <el-form ref="form" :model="form" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="订单编号" prop="orderNum">
              <el-input v-model="form.orderNum" placeholder="请输入公告标题" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="商品名" prop="productName">
              <el-input v-model="form.productName" placeholder="请输入商品名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="商品数量" prop="productCount">
              <el-input type="number" v-model="form.productCount" placeholder="请输入商品数量" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系人" prop="contactUserName">
              <el-input  v-model="form.contactUserName" placeholder="请输入联系人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="contactPhone">
              <el-input v-model="form.contactPhone" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位名称" prop="companyName">
              <el-input v-model="form.companyName" placeholder="请输入单位名称" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="快递地址" prop="shippingAddress">
              <el-input v-model="form.shippingAddress" placeholder="请输入快递地址" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {
  listPageOrderInfo, handle, updateSend, updata, updatePayment
} from '@/api/ums/orderInfo'
import { getNotice } from '@/api/system/notice'

export default {
  name: 'OmsOrderInfo',
  dicts: ['mark_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 购物车表格数据
      OmsOrderInfoList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productName: null,
        phone: null
      },
      // 表单参数
      form: {}
    }
  },
  created() {
    const { phone } = this.$route.query
    if (phone) {
      this.queryParams.phone = phone
    }
    this.getList()
  },
  methods: {
    /** 查询购物车列表 */
    getList() {
      this.loading = true
      const { pageNum, pageSize } = this.queryParams
      const query = { ...this.queryParams, pageNum: undefined, pageSize: undefined }
      const pageReq = { page: pageNum - 1, size: pageSize }
      listPageOrderInfo(query, pageReq).then(response => {
        const { content, totalElements } = response
        this.OmsOrderInfoList = content
        this.total = totalElements
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        status: 0,
        memberId: null,
        productId: null,
        pic: null,
        skuId: null,
        productName: null,
        spData: null,
        quantity: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      // this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加购物车'
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          updata(this.form).then(response => {
            this.$modal.msgSuccess('修改成功')
            this.open = false
            this.getList()
          })
        }
      })
    },
    /** 删除按钮操作 */
    handleUpdatehandle(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认修改订单为"' + row.productName + '"的数据项？').then(function() {
        return handle(row.id)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('修改成功')
      }).catch(() => {
      })
    },
    /** 删除按钮操作 */
    handleUpdateSend(row) {
      this.$modal.confirm('是否确认修改订单为"' + row.productName + '"的数据项？').then(function() {
        return updateSend(row.id)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('完成')
      }).catch(() => {
      })
    },
    /** 删除按钮操作 */
    handleUpdatePayment(row) {
      this.$modal.confirm('是否确认修改订单为"' + row.productName + '"的数据项？').then(function() {
        return updatePayment(row.id)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('完成')
      }).catch(() => {
      })
    },
    /** 修改按钮 */
    handleUpdate(row) {
      this.reset();
      this.form = row
      this.open = true;
      this.title = "修改";
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams
      this.$modal.confirm('是否确认导出所有购物车数据项？').then(() => {
        this.exportLoading = true
        return exportUmsMemberCart(queryParams)
      }).then(response => {
        this.$download.download(response)
        this.exportLoading = false
      }).catch(() => {
      })
    }
  }
}
</script>
<style lang="scss">
.product-container {
  display: flex;
  flex-direction: row;
  align-items: center;
  width: 180px;

  .product-item {
    margin: auto;
    width: 180px;

    .sp-data {
      font-size: 13px;
    }

    .quantity {
      font-weight: bold;
      font-size: 13px;
    }
  }
}

.el-table .my-cell {
  vertical-align: top
}
</style>
